package com.ww.springboot.boot.algorithm.leetcode1;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2025-07-14 10:18
 */
public class A1290二进制链表转整数 {

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1,new ListNode(0,new ListNode(1,null)));

        int decimalValue = getDecimalValue(listNode);
        System.out.println(decimalValue);
    }



    public static int getDecimalValue(ListNode head) {
        int total = 0;
        while (head != null){
            total = total * 2 + head.val;
            head = head.next;
        }
        return total;
    }


    /**
     * Definition for singly-linked list.
     */
    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}
